/*
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */

#ifndef _CODETEXT_H
#define _CODETEXT_H

#include <iostream>
#include <QPaintEvent>
#include <QResizeEvent>
#include <QSize>
#include <QWidget>
#include <QPainter>
#include <QTextBlock>
#include <QPlainTextEdit>
#include <QMessageBox>
#include <QTextStream>
#include <QRect>
#include <QVBoxLayout>
#include <QAction>
#include <QToolBar>
#include <QFile>
#include <QApplication>
#include <QStatusBar>

#include "highlighter.h"

class codeText;

class lineNumberArea : public QWidget{
	
	private:
		codeText *codeEditor;
	
	protected:
		void paintEvent(QPaintEvent *);
	
	public:
		lineNumberArea(codeText *);

		QSize sizeHint() const;
		
};

class codeText: public QPlainTextEdit{
	
	Q_OBJECT
	
	private:
		QWidget *lineArea;
		
	private slots:
		void updateLineNumberAreaWidth(int);
		void highlightCurrentLine();
		void updateLineNumberArea(const QRect &, int);

	protected:
		void resizeEvent(QResizeEvent *);

	public:
		codeText(QWidget * = 0);

		void lineNumberAreaPaintEvent(QPaintEvent *);
		int lineNumberAreaWidth();
		
		void highlighSpecificLine(int);

};

class codeEdit: public QWidget{

	Q_OBJECT

	private:
		QAction *copyAct;
		QAction *pasteAct;
		QAction *cutAct;
		QAction *saveAct;
		QAction *undoAct, *redoAct;
		
		QToolBar *toolBar;
		QVBoxLayout *vLayout;
		codeText *text;
		QString file;
		highlighter *high;
		QStatusBar *statusBar;
		
		bool modified, saved;
		
		void createActions();
		void createToolBar();
		void createCodeText();
		void createStatusBar();
		void statusChanged();
	
	signals:
		void textChanged();
	
	private slots:
		void documentWasModified();
		void changed();
		
	public slots:
		void saveSlot();
		bool save(QString &);
		
	public:
		codeEdit(QWidget *parent);
		
		void setFile(const QString &);
		QString getFile() const;
		bool isModified() const;
		bool isSaved() const;
		void setModified(bool);


};

#endif
